<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>专业信息管理</title>
	<meta name="decorator" content="default"/>
</head>
<body>
<div class="main-content">
    <tags:breadcrumb menuId="学校管理" />
    <div class="page-content">
		<div class="row">
			<div class="col-md-5" style="display: block;">
                <div class="widget-box">
                    <div class="widget-header">
                        <h4 class="smaller">
                            专业信息
                            <small>右边配置相关的专业</small>
                        </h4>
                    </div>
                    <div class="widget-body" style="padding: 1px;height: 500px;">
                        <div class="widget-main" style="padding: 1px;height: 98%;">
                            <iframe id="majorFrame" name="majorFrame" src="${ctx}/school/majorInfo/list?type=mini" style="overflow:visible;" scrolling="no" frameborder="no" width="100%" height="90%"></iframe>
                        </div>
                    </div>
                </div>
            </div>
			<div class="col-md-7">
                <div class="widget-box">
                    <div class="widget-header">
                        <h4 class="smaller">
                            <span style="font-weight: bold;color: #FF2F2F;margin-right: 5px;">${school.schoolName}</span>专业配置
                            <input type="button" id="submitMajorBtn" value="提交" style="float: right;margin-right: 5px;" class="btn btn-primary btn-mini" />
                        </h4>
                    </div>

                    <div class="widget-body" style="padding: 1px;height: 500px;">
                        <div class="widget-main" style="padding: 1px;height: 98%;">
                            <form id="selInfoForm" modelAttribute="school"  method="post" class="form-horizontal">
                                <input type="hidden" name="id" value="${school.id}"/>
                                <table id="majorTable" class="table table-striped table-bordered table-condensed">
                                    <thead>
                                    <tr>
                                        <th width="40%">专业名称</th>
                                        <th width="10%">专业代码</th>
                                        <th width="12%">是否重点</th>
                                        <th width="12%">是否特色</th>
                                        <th width="8%">排序</th>
                                        <th width="10%">&nbsp;</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <c:forEach items="${school.schoolMajorList}" var="major" varStatus="status">
                                        <tr>
                                            <td>
                                                <input type="hidden" name="schoolMajorList[${status.index}].majorName" value="${major.majorName}"/>
                                                <span>${major.majorName}</span>
                                            </td>
                                            <td>
                                                <input type="hidden" name="schoolMajorList[${status.index}].majorCode" value="${major.majorCode}"/>
                                                <span>${major.majorCode}</span>
                                            </td>
                                            <td>
                                                <input type="checkbox" name="schoolMajorList[${status.index}].isKeyPoint" value="1" <c:if test="${major.isKeyPoint eq '1'}">checked</c:if>/>
                                            </td>
                                            <td>
                                                <input type="checkbox" name="schoolMajorList[${status.index}].isCharacteristic" value="1" <c:if test="${major.isCharacteristic eq '1'}">checked</c:if>/>
                                            </td>
                                            <td>
                                                <input type="text" name="schoolMajorList[${status.index}].sort" value="${major.sort}" style="width: 50px;padding: 0px;"/>
                                            </td>
                                            <td>
                                                <a href="javascript:;" onclick="delMajor(this);" class='btn btn-warning btn-mini'>移除</a>
                                            </td>
                                        </tr>
                                    </c:forEach>
                                    </tbody>
                                </table>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
		</div>
    </div>
</div>
<script type="text/javascript">
	$(document).ready(function() {
        //提交信息
        $("#submitMajorBtn").click(function(){
            var url = "${ctx}/school/school/saveMajor";
            $.post(url,$("#selInfoForm").serialize(),function(data){
                if(data.success){
                    showNote("success", function () {
                        window.location.href = "${ctx}/school/school/list";
                    }, data.msg);
                }else {
                    showNote("error",function(){
                        return false;
                    },data.msg)
                }
            });
        });
	});

    //选择专业信息
    function addMajor(majorName,majorCode){
        var len = $("#majorTable tbody").find("tr").length;
        var trStr =
                "<tr>" +
                "<td>" +
                " <input type=\"hidden\" name=\"schoolMajorList["+len+"].majorName\" value=\""+majorName+"\"/>" +
                " <span>"+majorName+"</span>" +
                " </td>" +
                "<td>" +
                "    <input type=\"hidden\" name=\"schoolMajorList["+len+"].majorCode\" value=\""+majorCode+"\"/>" +
                "    <span>"+majorCode+"</span>" +
                "</td>" +
                "<td>" +
                "    <input type=\"checkbox\" name=\"schoolMajorList["+len+"].isKeyPoint\" value=\"1\"/>" +
                "</td>" +
                "<td>" +
                "    <input type=\"checkbox\" name=\"schoolMajorList["+len+"].isCharacteristic\" value=\"1\"/>" +
                "</td>" +
                "<td>" +
                "    <input type=\"text\" name=\"schoolMajorList["+len+"].sort\" value=\""+len+"\" style=\"width: 50px;padding: 0px;\"/>" +
                "</td>" +
                "<td>" +
                "    <a href='javascript:;' onclick=\"delMajor(this);\" class='btn btn-warning btn-mini'>移除</a>" +
                "</td>" +
                "</tr>";
        $("#majorTable tbody").append(trStr);
    }

    function delMajor(obj){
        $(obj).parent().parent().remove();
    }

	function page(n,s){
		$("#pageNo").val(n);
		$("#pageSize").val(s);
		$("#searchForm").submit();
		return false;
	}
</script>
</body>
</html>